class Animal {
    public String name;
    public int age;



    public  void eat() {
        System.out.println(name + "正在吃饭！");
    }
}
class Dog extends Animal {


    public void wangwang() {
        System.out.println(name +" 正在汪汪叫！");
    }
    @Override
    public void eat() {
        System.out.println(name+ " 正在吃狗粮!");
    }
}
class  Bird extends  Animal{
    public String wing;//翅膀

    public void fly() {
        System.out.println(name + " 正在飞！");
    }
    @Override
    public  void eat() {
        System.out.println(name +" 正在吃鸟粮！");
    }
}
public class Test{
    public static void main(String[] args) {
        Animal animal = new Bird();//向上转型
       /* //向下转型
        //Dog dog = animal;//这样写会报错，dog和animal数据类型不同
        Dog dog =(Dog)animal;//需要将animal类型强制类型转换成Dog类
        dog.name = "大黄";
        dog.wangwang();
        System.out.println("================");*/
        //可以理解为：判断animal这个引用是不是引用了Bird对象
        if(animal instanceof Bird){
            Bird bird =(Bird) animal;
            bird.name = "圆圆";
            bird.fly();
        }
    }


    public static void function(Animal animal){
        animal.eat();
    }
    public static void main1(String[] args) {
        Animal animal = new Dog();
        animal.name="大黄";
        function(animal);
        System.out.println("=============");
        Animal animal1 = new Bird();
        animal1.name = "圆圆";
        function(animal1);
    }
}
